package com.feheadline.ml.classification;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;

import com.aliasi.classify.ScoredClassification;
import com.aliasi.classify.ScoredClassifier;

public class TestClassifier {

	@SuppressWarnings("unchecked")
	public String getCategory(String text, String modelFile) {
		String category = null;
		try {
			ObjectInputStream oi = new ObjectInputStream(new FileInputStream(modelFile));
			ScoredClassifier<CharSequence> compiledClassifier = (ScoredClassifier<CharSequence>) oi
					.readObject();
			oi.close();
			ScoredClassification channels = compiledClassifier.classify(text
					.subSequence(0, text.length()));
			category = channels.bestCategory();

		} catch (ClassNotFoundException | IOException e) {
			e.printStackTrace();
		}
		return category;
	}
}
